Namespace RSS
    Public Class clRssCanal
        Implements iRssCanal

        Dim _titulo As String
        Dim _link As String
        Dim _descripcion As String
        Dim _fechaPub As DateTime = DateTime.Now
        Dim _ttl As Integer = -1
        Dim _imagen As strRssImagen
        Dim _items As New Collections.Generic.List(Of RSS.iRssItem)

        Public Sub New(ByVal titulo As String, ByVal link As String, ByVal descripcion As String)
            _titulo = titulo
            _link = link
            _descripcion = descripcion
        End Sub
#Region "Propiedades"
        Public Property titulo() As String Implements iRssCanal.titulo
            Get
                Return _titulo
            End Get
            Set(ByVal value As String)
                _titulo = value
            End Set
        End Property
        Public Property descripcion() As String Implements iRssCanal.descripcion
            Get
                Return _descripcion
            End Get
            Set(ByVal value As String)
                _descripcion = value
            End Set
        End Property
        Public Property fechaPublicacion() As DateTime Implements iRssCanal.fechaPublicacion
            Get
                Return _fechaPub
            End Get
            Set(ByVal value As DateTime)
                _fechaPub = value
            End Set
        End Property
        Public Property ttl() As Integer Implements iRssCanal.ttl
            Get
                Return _ttl
            End Get
            Set(ByVal value As Integer)
                _ttl = value
            End Set
        End Property
        Public Property link() As String Implements iRssCanal.link
            Get
                Return _link
            End Get
            Set(ByVal value As String)
                _link = value
            End Set
        End Property
        Public Property imagen() As RSS.strRssImagen Implements iRssCanal.imagen
            Get
                Return _imagen
            End Get
            Set(ByVal value As RSS.strRssImagen)
                _imagen = value
            End Set
        End Property
#End Region

        Public ReadOnly Property RFC822Date() As String
            Get
                Return mdRssDeclaraciones.GetRFC822Date(_fechaPub)
            End Get
        End Property


        Public Property Items() As Collections.Generic.List(Of RSS.iRssItem)
            Get
                Return _items
            End Get
            Set(ByVal value As Collections.Generic.List(Of RSS.iRssItem))
                _items = value
            End Set
        End Property

        Public Function generarCanal(ByVal sw As IO.StringWriter) As String
            Dim writer As New Xml.XmlTextWriter(sw)
            Dim aux As String
            With writer
                .WriteStartElement("channel")
                .WriteElementString("title", _titulo)
                .WriteElementString("link", _link)
                .WriteElementString("description", _descripcion)
                .WriteElementString("pubDate", RFC822Date)

                If ttl > -1 Then .WriteElementString("ttl", _ttl)

                Dim i As RSS.iRssItem

                For Each i In Items
                    .WriteStartElement("item")
                    .WriteElementString("title", i.titulo)
                    .WriteElementString("link", i.link)
                    .WriteElementString("description", i.descripcion)
                    .WriteElementString("pubDate", RSS.GetRFC822Date(i.fechaPublicacion))
                    .WriteEndElement()
                Next
                .WriteEndElement()

                aux = sw.ToString
                .Close()
            End With
            Return aux
        End Function


        Public Function getItems() As System.Collections.Generic.List(Of iRssItem) Implements iRssCanal.getItems
            Return Items
        End Function
    End Class

End Namespace

